package com.example.seckill.utils;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @Author: caowj1217
 * @Date: 2021/8/9下午1:33
 * @Description:
 */
public class RedisFactory {
    public static JedisPoolConfig getPoolConfig() throws IOException {
		Properties properties = new Properties();

		InputStream in = RedisFactory.class.getClassLoader().getResourceAsStream("application.properties");

		try {
			properties.load(in);
			JedisPoolConfig config = new JedisPoolConfig();
			config.setMaxIdle(Integer.parseInt(properties.getProperty("maxIdle", "100")));
			config.setMinIdle(Integer.parseInt(properties.getProperty("minIdle", "1")));
			config.setMaxTotal(Integer.parseInt(properties.getProperty("maxTotal", "1000")));
			return config;
		} finally {
			in.close();
		}

	}

	public static RedisClient getDefaultClient(){
		JedisPool pool = new JedisPool("127.0.0.1",6379, null,"123456");
		RedisClient client = new RedisClient(pool);
		return client;
	}
}
